Socket
Socket
Sign inDemoInstall

ajv-i18n

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ajv-i18n

Internationalised error messages for ajv JSON-Schema validator


Version published
Weekly downloads
121K
increased by3.14%
Maintainers
1
Weekly downloads
 
Created

What is ajv-i18n?

The ajv-i18n package provides internationalization (i18n) support for the Ajv JSON schema validator. It allows you to generate error messages in different languages, making it easier to localize your applications.

What are ajv-i18n's main functionalities?

Localizing error messages

This feature allows you to localize error messages generated by Ajv. In this example, the error messages are localized to Chinese using the `localize.zh` function.

const Ajv = require('ajv');
const localize = require('ajv-i18n');

const ajv = new Ajv();
const schema = { type: 'object', properties: { foo: { type: 'string' } }, required: ['foo'], additionalProperties: false };
const validate = ajv.compile(schema);
const data = { bar: 2 };

const valid = validate(data);
if (!valid) {
  localize.zh(validate.errors); // Localize errors to Chinese
  console.log(validate.errors);
}

Supporting multiple languages

This feature demonstrates the ability to support multiple languages. In this example, the error messages are localized to Russian using the `localize.ru` function.

const Ajv = require('ajv');
const localize = require('ajv-i18n');

const ajv = new Ajv();
const schema = { type: 'object', properties: { foo: { type: 'string' } }, required: ['foo'], additionalProperties: false };
const validate = ajv.compile(schema);
const data = { bar: 2 };

const valid = validate(data);
if (!valid) {
  localize.ru(validate.errors); // Localize errors to Russian
  console.log(validate.errors);
}

Other packages similar to ajv-i18n

Keywords

FAQs

Package last updated on 24 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc